﻿using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace ART.BLL
{
    /// <summary>
    /// 分页列表类
    /// Create by YAO Ming
    /// </summary>
    public static class GetListByPage
    {
        ///<summary>
        ///分页参数配置
        ///</summary>
        public static DataSet GetDataSet(string Table, string Field, string Where, string GroupBy, string OrderBy, string PrimaryKeyField, int PageIndex, int PageSize, int IsCount,double days)
        {

            #region ______参数______
            SqlParameter[] paras = {
                                       new SqlParameter("@Table",SqlDbType.VarChar,500),
                                       new SqlParameter("@Field",SqlDbType.VarChar,500),
                                       new SqlParameter("@Where",SqlDbType.VarChar,3000),
                                       new SqlParameter("@GroupBy",SqlDbType.VarChar,500),
                                       new SqlParameter("@OrderBy",SqlDbType.VarChar,500),
                                       new SqlParameter("@PrimaryKeyField",SqlDbType.VarChar,50),
                                       new SqlParameter("@PageIndex",SqlDbType.Int),
                                       new SqlParameter("@PageSize",SqlDbType.Int),
                                       new SqlParameter("@IsCount",SqlDbType.Int),
                                   };
            paras[0].Value = Table;
            paras[1].Value = Field;
            paras[2].Value = Where;
            paras[3].Value = GroupBy;
            paras[4].Value = OrderBy;
            paras[5].Value = PrimaryKeyField;
            paras[6].Value = PageIndex;
            paras[7].Value = PageSize;
            paras[8].Value = IsCount;

            #endregion


            string CacheName = "/PAGE/GetListByPage_GetDataSet_" + Table + "_" + Field + "_" + Where + "_" + GroupBy + "_" + OrderBy + "_" + PrimaryKeyField + "_" + PageIndex + "_" + PageSize;
            object cache = ART.Cache.LRSCache.GetCacheService().RetrieveObject(CacheName);
            if (cache == null)
            {
                DataSet ds = ART.Data.SqlHelper.ExecStoreDataSet("GetListByPage", paras);
                ART.Cache.LRSCache.GetCacheService().AddObject(CacheName, ds, (int)days);
                return ds;
            }
            return (DataSet)cache;
         
        }


        ///<summary>
        ///分页参数配置
        ///</summary>
        public static DataSet GetDataSet_NoCache(string Table, string Field, string Where, string GroupBy, string OrderBy, string PrimaryKeyField, int PageIndex, int PageSize, int IsCount)
        {

            #region ______参数______
            SqlParameter[] paras = {
                                       new SqlParameter("@Table",SqlDbType.VarChar,500),
                                       new SqlParameter("@Field",SqlDbType.VarChar,500),
                                       new SqlParameter("@Where",SqlDbType.VarChar,3000),
                                       new SqlParameter("@GroupBy",SqlDbType.VarChar,500),
                                       new SqlParameter("@OrderBy",SqlDbType.VarChar,500),
                                       new SqlParameter("@PrimaryKeyField",SqlDbType.VarChar,50),
                                       new SqlParameter("@PageIndex",SqlDbType.Int),
                                       new SqlParameter("@PageSize",SqlDbType.Int),
                                       new SqlParameter("@IsCount",SqlDbType.Int),
                                   };
            paras[0].Value = Table;
            paras[1].Value = Field;
            paras[2].Value = Where;
            paras[3].Value = GroupBy;
            paras[4].Value = OrderBy;
            paras[5].Value = PrimaryKeyField;
            paras[6].Value = PageIndex;
            paras[7].Value = PageSize;
            paras[8].Value = IsCount;

            #endregion

            return ART.Data.SqlHelper.ExecStoreDataSet("GetListByPage", paras);
              
        }
    
    
    }
}
